/**
 * @description Model Manifest
 *
 * @author Xiongmao
 */

var db = require('../db');

module.exports = db.model('User', {
    tableName: 'users',
    hasTimestamps: true,

    role() {
        return this.belongsTo('Role', 'role_id');
    },
    department() {
        return this.belongsTo('Department', 'department_id');
    },
    parse(attrs) {
        delete attrs.pwd;

        return attrs;
    },
    nums() {
        return this.hasMany('Repair', 'repairer_id')
        .query(qb => {
            qb.count('id as count');
            qb.select('id', 'status');
            qb.orderBy('status');
            qb.groupBy('status', 'repairer_id');
        });
    }
});
